<?php
Class LogModel
{
	public function __construct()
	{
		$this->db = Yaf_Registry::get('_db');
	}
	
	public function selectAll($start = 0, $length = 20, $searchkey = '')
	{
		$wheresql = ' where 1=1 ';
		if (isset($searchkey) && !empty($searchkey)){
			$wheresql .= " and operator like '%$searchkey%'";
		}
	
		// 获取总数
		$countsql = "select count(id) from t_log " . $wheresql;
		$total = $this->db->get_var($countsql);
	
		// 获取分页数据
		$sql = "select * from t_log " . $wheresql . " order by createtime desc limit $start, $length";
	
		$result = $this->db->get_results($sql);
	
		return array($total, $result);
	}
	
	public function insert($info)
	{
		$operator = $info['operator'];
		$operate = $info['operate'];
		$uri = $info['uri'];
		$ip = $info['ip'];
		$time = date('Y-m-d H:i:s');
	
		$sql = "insert into t_log(operator, operate, uri, ip, createtime)
		values('$operator', '$operate', '$uri', '$ip', '$time')";

		$result = $this->db->query($sql);
		return $result;
	}
	
	public function delete($start,$end){
		$start = $start;
		$end = $end;
		$sql = "delete from t_log where createtime > '$start' and createtime < '$end'";
		$result = $this->db->query($sql);
		return $result;
	}
}